﻿/*
 * Licensed under the Apache License, Version 2.0 (http://www.apache.org/licenses/LICENSE-2.0)
 * See https://Joylogic.com/aspnet-contrib/AspNet.Security.OAuth.Providers
 * for more information concerning the license and the contributors participating to this project.
 */

using System.Security.Claims;
using Microsoft.AspNetCore.Authentication;
using Microsoft.AspNetCore.Authentication.OAuth;
using static AspNet.Security.OAuth.Joylogic.JoylogicAuthenticationConstants;

namespace AspNet.Security.OAuth.Joylogic
{
    /// <summary>
    /// Defines a set of options used by <see cref="JoylogicAuthenticationHandler"/>.
    /// </summary>
    public class JoylogicAuthenticationOptions : OAuthOptions
    {
        public JoylogicAuthenticationOptions()
        {
            ClaimsIssuer = JoylogicAuthenticationDefaults.Issuer;

            CallbackPath = JoylogicAuthenticationDefaults.CallbackPath;

            AuthorizationEndpoint = JoylogicAuthenticationDefaults.AuthorizationEndpoint;
            TokenEndpoint = JoylogicAuthenticationDefaults.TokenEndpoint;
            UserInformationEndpoint = JoylogicAuthenticationDefaults.UserInformationEndpoint;
            
            ClaimActions.MapJsonKey(ClaimTypes.NameIdentifier, "id");
            ClaimActions.MapJsonKey(ClaimTypes.Name, "login");
            ClaimActions.MapJsonKey(ClaimTypes.Email, "email");
            ClaimActions.MapJsonKey(Claims.Name, "name");
            ClaimActions.MapJsonKey(Claims.Url, "website");
        }

        /// <summary>
        /// Gets or sets the address of the endpoint exposing
        /// the email addresses associated with the logged in user.
        /// </summary>
        public string UserEmailsEndpoint { get; set; } = JoylogicAuthenticationDefaults.UserEmailsEndpoint;
    }
}
